import {Dialog, GridMixin, Util,I18Parse,JsConstant} from '@lowcode/jpaas-common-lib'
import FormBoListApi from '@/api/form/core/formBoList'
import FormCustomQueryApi from "@/api/form/core/formCustomQuery";
import RenderConfig from "@/views/modules/form/core/RenderConfig";
import RowControls from "@/views/modules/form/core/RowControls";
import FormBoListBtnServerScript from "@/views/modules/form/core/FormBoListBtnServerScript";
import MiniQuery from "@/views/modules/form/core/MiniQuery";
import DialogBox from "../../../assets/js/DialogBox";
import InstColumn from "@/views/modules/form/core/columnPersonalized/InstColumn.vue";
import FormPrintLodopList from "@/views/modules/form/core/FormPrintLodopList";
import FormPdfTemplateList from "@/views/modules/form/core/FormPdfTemplateList";
import FormListOpenUreportDialog from "@/views/modules/form/core/FormListOpenUreportDialog.vue";
import FormBoListConfigOpenFormDialog from "@/views/modules/form/core/FormBoListConfigOpenFormDialog";
import FormBoListConfigOpenListDialog from "@/views/modules/form/core/FormBoListConfigOpenListDialog";
import FormListOpenCustomDialog from "@/views/modules/form/core/FormListOpenCustomDialog";
import FormBoListCellHeader from "@/views/modules/form/core/FormBoListCellHeader";
import renderConfig_link from "@/views/modules/form/core/cellRender/renderConfig_link";
import FormBoListSearchGroup from "@/views/modules/form/core/FormBoListSearchGroup";
import {cololumRenderTypeList} from "@/views/modules/form/core/js/CololumRenderTypes";
import FormWordTemplateDialog from "@/views/modules/form/core/FormWordTemplateDialog";
import FormBoListConfigFormTranDialog from "@/views/modules/form/core/FormBoListConfigFormTranDialog";
import SelectConfig from "@/views/modules/form/core/SelectConfig";
import {scriptLib} from '@/api/form/core/scriptLib';
import ScriptInsertAry from '@/views/modules/share/ScriptLib';

import ScriptVm from "@/api/form/core/ScriptVm";

import reloadColumnDialog from "@/views/modules/form/core/listLayout/reloadColumnDialog.vue";

import listLayoutDialog from "@/views/modules/form/core/listLayout/listLayoutDialog";
import ListMethodDialog from "@/views/modules/form/core/dialog/ListMethodDialog.vue";
import FormLiteFlowDialog from "@/views/modules/form/bo/FormLiteFlowDialog";
import ApiFormCoreLang from "@/locales/lang/impl/form/apiFormCoreLang";
import CustomControlDialog from "@/views/modules/form/core/formsolution/CustomConfigDialog/CustomControlDialog";

export default {
    mixins: [GridMixin,ScriptVm],
    created() {
        this.getCurrentI18n();
        this.getFields();

        this.scriptInsertAry.push(this.commonJsLib);
        this.scriptInsertAry.push(this.flowJsLib);
        this.scriptInsertAry.push(this.tableJsLib);
    },
    computed: {
        paramData: function () {
            var data = this.$refs["table_searchConf"].getData();
            var tmp = [];
            data.map(field => {
                if (field.type == 'income') {
                    var obj = {label: field.fieldLabel, value: field.fieldName};
                    tmp.push(obj);
                }
            });
            return tmp;
        },
        headFields(){
            let fields= this.fieldDatas.map(field=>{
                return {label:field.value,value:field.value};
            });
            return fields;
        },
        importColumnsExcel(){
            if(this.excelConfJson.specialSn){
                return this.headerColumnsExcel;
            }
            else{
                return this.headerColumnsExcel.filter(item=>{
                    return item.dataIndex!='sn';
                });
            }
        }

    },
    methods: {
        i18n2(name, text, key) {
            return this.$ti18(name, text, "apiFormCore", key);
        },
        i18n3(name, text, key) {
            return this.$ti18(name, text, "formCellRender", key);
        },
        clearFilterConfig(record){
            let self_=this;
            this.$confirm({
                title: this.$ti18('rxMsa.tipsInfo','提示信息'),
                content: self_.i18n2('sureDelete','确认删除配置吗?'),
                onOk() {
                    self_.$set(record,"filterConfig","");
                    self_.$set(record,"isSeted",false);
                    self_.$forceUpdate();
                },
                onCancel() {},
                okText:this.$ti18('rxForm.ackBtn','确认'),
                cancelText:this.$ti18('rxForm.cancelBtn','取消')
            });
        },
        oneKFilterConf(){
            for(var i=0;i<this.headerFields.length;i++){
                let row=this.headerFields[i];
                this.setFilterConfByChild(row);
                if(row.isSeted){
                    continue;
                }
                this.setInitFilterConfig(row);
            }
        },
        setFilterConfByChild(record){
            if(!record.children || record.children.length==0){
                return;
            }
            for(var i=0;i<record.children.length;i++){
                let row=record.children[i];
                this.setFilterConfByChild(row);
                if(row.isSeted){
                    continue;
                }
                this.setInitFilterConfig(row);
            }
        },
        setInitFilterConfig(record){
            let dataType = record.dataType;

            let filterConfig={
                "type": "query",
                "autoFilter": "YES",
                "isSeted": false,
                "fc": "",
                "fieldOp": "EQ",
                "dataType": dataType,
                "tablePre": "",
                "fieldName": record.field,
                "fieldLabel": record.header,
                "multiSelect": false,
                "from": "self",
                "i18nJson": this.initI18nStr(record),
            }

            if(['int','number'].contains(dataType)){
                //数字类型
                filterConfig.fc = "number";
            }else if(dataType =='date'){
                //日期类型
                filterConfig.fc = "datepicker";
            }else{
                //其他全部按照字符串
                filterConfig.fieldOp ="LK";
                filterConfig.fc = "textbox";
            }
            this.$set(record,"filterConfig",JSON.stringify(filterConfig));
            this.$set(record,"isSeted",true);
        },
        initI18nStr(record){
            var i18nJson = {};
            i18nJson[this.i18nCurrent] = record.header;
            return JSON.stringify(i18nJson);
        },
        showFilterConfigEditor(event,record,table) {
            if(!table){
                table = this.$refs["table_" + this.activeKey];
            }
            var row = record//table.getSelectedRow();
            row.fc = "columsearch";
            var conf = {
                component: MiniQuery,
                title: this.i18n2('searchConfig','搜索条件配置'),
                curVm: this,
                data: {row: row, fieldDatas: this.fieldDatas,queryAry:table.getData(),showDefault:true},
                widthHeight: ['900px', '600px'],
                shade:true
            };
            Util.open(conf, function (action) {
                if (action != 'ok') {
                    return;
                }
                var data = this.getData();
                record.isSeted = true;
                record.filterConfig = data.filterConfig;
                table.$forceUpdate();
            });
        },
        editListLayoutConfig(type){
            var self=this;
            var conf = {
                component: listLayoutDialog,
                title: this.i18n2('layoutConfig','看板布局配置'),
                curVm: this,
                data: {
                    type: type,
                    curAppObj:this.curAppObj,
                    fieldDatas:this.fieldDatas,
                    config:this.listLayout[type].config
                },
                max:true
            }
            Util.open(conf, function (action, data) {
                if (action != 'ok') {
                    return
                }
                self.listLayout[type].config=data;
            })
        },
        loadConstants() {
            FormCustomQueryApi.getConstants().then(data => {
                this.constantField = this.constantField.concat(data.map(item => {
                    return {label: item.val, value: item.key}
                }));
            })
        },
        tabChange(activeKey){
            if(activeKey==='returnColumn' && this.mdl.useCondSql==='WEBREQ'){
                let self_=this;
                this.returnFields=this.headerFields.map(item=>{
                    for(var i=0;i<self_.returnFields.length;i++){
                        if(self_.returnFields[i].field===item.field && self_.returnFields[i].header===item.header){
                            return {isReturn:self_.returnFields[i].isReturn,visible:self_.returnFields[i].visible,header:item.header,field:item.field}
                        }
                    }
                    return {isReturn:false,visible:false,header:item.header,field:item.field}
                });
            }else if(activeKey=='permissionConf'){
                this.initPermissionConf();
            }
        },
        initPermissionConf(){
            var columnConf=this.getTable("columnConf");
            var columns=columnConf.getData();
            //剔除空行
            var newColumns=[];
            for(var i=0,j=columns.length;i<j;i++){
                if(columns[i].header){
                    newColumns.push(columns[i]);
                }
            }
            var toolBar=this.getTable("toolBar");
            var topBtnsJson=toolBar.getData();
            var dataConf=this.getTable("dataConf");
            var dataConfJson=dataConf.getData();
            var mobileConfJson={};
            var mobileConf = this.$refs.mobile.getData();
            if (mobileConf.success) {
                mobileConfJson=mobileConf.data;
            }
            this.getTable("permissionConf").loadData({
                dataConf:dataConfJson,
                buttons:topBtnsJson,
                columns:newColumns,
                mobileConf:mobileConfJson
            });
        },
        reloadColumns() {
            FormBoListApi.reloadColumns(this.pkId,false).then(res => {
                var reloadFields = res.data;
                var self=this;
                self.fieldDatas=reloadFields.map(field=>{
                    return {label: field.header, value: field.field, key: field.dataType}
                });


                var conf = {
                    component: reloadColumnDialog,
                    title: self.i18n2('reloadTable','重新加载表头'),
                    curVm: this,
                    data: {reloadFields: reloadFields},
                    widthHeight: ['800px', '600px']
                };
                Util.open(conf, function (action,data) {
                    if (action !== 'ok') {
                        return;
                    }
                    data.forEach(item=>{
                        if(!item.hasOwnProperty('rowMerge')){
                            item.rowMerge = false;
                        }
                        let has =  self.headerFields.find(o=>o.field === item.field)
                        if(has){
                            has.header=item.header;
                        }else {
                            delete item.visible;
                            self.headerFields.push(item);
                        }
                    })
                });
            });
        },

        reloadColumnsExcel() {
            var self_=this;
            let excelColumns = Util.deepClone(this.excelConfJson.headerColumnsExcel);
            let fieldKeys = [];
            excelColumns.forEach(item => {
                fieldKeys.push(item.field);
            });
            FormBoListApi.reloadColumns(this.pkId,false).then(res => {
                self_.returnAllFields=res.data;
                let conf = {
                    component: reloadColumnDialog,
                    title:  self_.i18n('list.reloadExcel', '重新加载Excel列头'),
                    curVm: this,
                    data: {
                        reloadFields: self_.returnAllFields,
                        showCommonField:false,
                        checkedFields:fieldKeys
                    },
                    widthHeight: ['800px', '600px']
                };
                Util.open(conf, function (action,data) {
                    if (action != 'ok') {
                        return;
                    }
                    let headerColumnsExcel = [];
                    for (let i = 0; i < data.length; i++) {
                        let column = data[i];
                        let findColumn = excelColumns.find(item=>{
                            return item.field == column.field;
                        })
                        if(!findColumn){
                            headerColumnsExcel.push({...column,required:false});
                        }else {
                            headerColumnsExcel.push(findColumn);
                        }
                    }
                    self_.excelConfJson.headerColumnsExcel = headerColumnsExcel;
                });
            });
        },
        //重新加载返回字段
        reloadReturnColumn(){
            var self_=this;
            FormBoListApi.reloadColumns(this.pkId,false).then(res => {
                self_.returnAllFields=res.data;
            });
        },
        selectReturnColumn() {
            var self_=this;
            FormBoListApi.reloadColumns(this.pkId,false).then(res => {
                self_.returnAllFields=res.data;
                let conf = {
                    component: reloadColumnDialog,
                    title:  self_.i18nCustomQuery('isButton.columnHeader', '列头设置'),
                    curVm: this,
                    data: {reloadFields: self_.returnAllFields},
                    widthHeight: ['800px', '600px']
                };
                Util.open(conf, function (action,data) {
                    if (action != 'ok') {
                        return;
                    }
                    self_.addReturnData(data);
                });
            });

        },
        addReturnData(data) {
            var json = this.getReturnJson(this.returnFields);
            for (var i = 0; i < data.length; i++) {
                var obj = data[i];
                if (!json[obj.field]) {
                    let row={
                        header:obj.header,
                        field:obj.field,
                        displayField:false
                    }
                    this.returnFields.push(row);
                }
            }
        },
        getReturnJson(data) {
            var obj = {};
            for (var j = 0; j < data.length; j++) {
                obj[data[j].field] = 1;
            }
            return obj;
        },
        removeReturnFields(id) {
            this.$refs["table_" + this.activeKey].removeRows();
        },
        moveUpReturn(id) {
            this.$refs["table_" + this.activeKey].moveUp();
        },
        moveDownReturn(id) {
            this.$refs["table_" + this.activeKey].moveDown();
        },
        addRow(row) {
            this.$refs["table_" + this.activeKey].addRow(row);
        },
        addTreeRow(row){
            var selRow=this.$refs["table_" + this.activeKey].getSelectedRow();
            if(!selRow){
                this.addRow(row);
                return;
            }
            if(selRow.type!='conditionAnd' && selRow.type!='conditionOr'){
                this.$message.error(this.i18n2('onlyCondition','只能加在条件分组下面！'));
                return;
            }
            if(!selRow.children){
                selRow.children=[];
            }
            row[this.$refs["table_" + this.activeKey].parentField]=selRow[this.$refs["table_" + this.activeKey].idField];
            this.$refs["table_" + this.activeKey].addItem(selRow.children,row);
            this.$forceUpdate();
        },
        removeRow() {
            var table=this.$refs["table_" + this.activeKey];
            table.removeRows();
            table.selectedRowKeys=[];
            table.selectedRows=[];
            this.$forceUpdate();
        },
        upRow() {
            this.$refs["table_" + this.activeKey].moveUp();
        },
        topUp(){
            this.$refs["table_" + this.activeKey].moveTopUp();
        },
        bottomUp(){
            this.$refs["table_" + this.activeKey].moveBottomUp();
        },
        downRow() {
            this.$refs["table_" + this.activeKey].moveDown();
        },
        mainHeaderRow() {
            this.$refs["table_" + this.activeKey].toMain();
        },
        subHeaderRow() {
            let table=this.$refs["table_" + this.activeKey];
            if(this.activeKey=="toolBar"){
                let row=table.getSelectedRow();
                if(row.toolPid!=0){
                    this.$message.error(this.i18n2('buttonsToSub','功能按钮最多下降一级！'));
                    return;
                }
            }
            table.toSub();
        },
        expand() {
            var table = this.$refs["table_" + this.activeKey];
            table.expand();
        },
        collapse() {
            var table = this.$refs["table_" + this.activeKey];
            table.collapse();
        },
        rowControlConfig() {
            var table = this.$refs["table_" + this.activeKey];
            var row = table.getSelectedRow();
            if (row == null || (!row.control)) {
                this.$message.error(this.i18n2('selectCtl','请选择行与编辑控件！'));
                return;
            }
            var control= this.rowControls.find(item=>{
                if(item.value==row.control){
                    return item;
                }
            });
            var conf = {
                component: RowControls,
                title: this.i18n2('renderConfig','字段渲染配置') + '(' + control.label + ')',
                curVm: this,
                data: {row: row, curFields: this.fieldDatas},
                widthHeight: ['800px', '600px']
            };
            Util.open(conf, function (action) {
                if (action != 'ok') {
                    return;
                }
                var data = this.getData();
                table.updateRow(row,{controlConf:JSON.stringify(data)});
            });
        },
        cellHeaderConfig(){
            var table = this.$refs["table_" + this.activeKey];
            var rows = table.getSelectedRows();
            if(rows.length!=1){
                this.$message.warn(this.i18n2('onlyRecord','请选择一行记录！'));
                return;
            }
            var conf = {
                component: FormBoListCellHeader,
                title: this.i18n2('colConfig','列头渲染配置'),
                curVm: this,
                data: {render: rows[0]},
                widthHeight: ['800px', '600px'],
                shade:true
            };

            Util.open(conf, function (action) {
                if (action != 'ok') {
                    return;
                }
                var data=this.getData();
                table.updateRow(rows[0],{customTitle:data.customTitle});
            });
        },
        getCurrentI18n(){
            this.i18nCurrent= window.localStorage.getItem("language");
            if(!this.i18nCurrent){
                this.i18nCurrent=this.i18nDefault;
            }
        },
        loadCurrent(data,text) {
            if(data.length===0){
                return [];
            }
            for (var i = 0; i < data.length; i++) {
                var obj = data[i];
                if(!obj.i18nJson){
                    continue;
                }
                let i18nJson=JSON.parse(obj.i18nJson);
                if(!i18nJson[this.i18nCurrent]){
                    continue;
                }
                obj[text]=i18nJson[this.i18nCurrent];
            }
            return data;
        },
        updateI18nName(record,text) {
            let i18nJson=this.getI18nJson(record,text);
            i18nJson[this.i18nCurrent]=record[text];
            var newRow={
                i18nJson:JSON.stringify(i18nJson)
            };
            let table = this.$refs["table_" + this.activeKey];
            table.updateRow(record,newRow);
            table.$forceUpdate();
        },
        getI18nJson(row,text){
            let i18nJson={};
            let i18nConf =row.i18nJson;
            if(i18nConf){
                i18nJson=JSON.parse(i18nConf);
                let val=i18nJson[this.i18nCurrent];
                if(!val){
                    i18nJson[this.i18nCurrent]=row[text];
                }
            }else {
                i18nJson[this.i18nCurrent] = row[text];
                i18nJson[this.i18nDefault] = row[text];
            }
            //i18nJson[this.i18nDefault] = row[text];
            return i18nJson;
        },
        editI18nName(record,text) {
            let row =record;
            let table = this.$refs["table_" + this.activeKey];
            let self_ = this;
            let conifg = {
                curVm: this,
                widthHeight: ['800px', '600px'],
                data: {
                    i18nJson: this.getI18nJson(row,text)
                }
            }
            Dialog.openI18nDialog(conifg, function (action, data) {
                row[text] = data[self_.i18nCurrent];
                var newRow={
                    i18nJson:JSON.stringify(data)
                };
                table.updateRow(row,newRow);
                table.$forceUpdate();
            });
        },
        cellRenderConfig(event,record,table) {
            if(!table){
                table = this.$refs["table_" + this.activeKey];
            }
            var row = record//table.getSelectedRow();
            if (!row.renderType) {
                this.$message.error(this.i18n2('chooseMethod','请选择渲染方式！'));
                return;
            }
            var renderConfig=this.getColumnRender(row.renderType);
            var wh=renderConfig.widthHeight;
            var conf = {
                component: RenderConfig,
                title: this.i18n2('renderConfig','字段渲染配置') + '(' + renderConfig.title + ')',
                curVm: this,
                data: {render: row, curFields: this.fieldDatas,listId:this.pkId,rowEdit:this.mdl.rowEdit,boDefId:this.boDefId},
                widthHeight: wh,
                shade:true,
                zIndex:999
            };
            if(renderConfig.max){
                conf['max'] = true
            }

            Util.open(conf, function (action) {
                if (action != 'ok') {
                    return;
                }

                var data=this.getData();
                var format=data.format;
                var field=data.field;
                var dataType=data.dataType;
                var dataType_name=data.dataType_name;
                var newRow={renderConf:JSON.stringify(data)};
                if(field){
                    newRow.field=field;
                }
                if(format){
                    newRow.format=format;
                }
                if(dataType){
                    newRow.dataType=dataType;
                }
                if(dataType_name){
                    newRow.dataType_name=dataType_name;
                }
                row.isSetedRender = true;
                if(data && (data.isShowPreview!=null || data.isShowDown!=null)){
                    newRow.fileRenders={}
                    Object.assign(newRow.fileRenders,data)
                }
                table.updateRow(row,newRow);
                table.$forceUpdate();
            });
        },
        clearRenderSetting(record,type){
            let self_=this;
            this.$confirm({
                title: this.$ti18('rxMsa.tipsInfo','提示信息'),
                content: self_.i18n2('sureDelete','确认删除配置吗?'),
                onOk() {
                    if(type=='render'){
                        self_.$set(record,"renderConf","");
                    }else if(type=='link'){
                        self_.$set(record,"linkConf","");
                    }
                    if(!record.renderConf && !record.linkConf ){
                        self_.$set(record,"isSetedRender",false);
                    }
                    self_.$forceUpdate();
                },
                onCancel() {},
                okText:this.$ti18('rxForm.ackBtn','确认'),
                cancelText:this.$ti18('rxForm.cancelBtn','取消')
            });

        },
        openSelectConfig(record){
            if (!record.selectConfig) {
                record.selectConfig = "";
            }
            var config = {
                curVm: this, widthHeight: ['800px', '600px'],
                component: SelectConfig,
                data: {
                    config: record.selectConfig
                },
                title: this.i18n2('dropDown','下拉框配置')
            };
            Util.open(config, function (action, data) {
                if (action == "ok") {
                    record.selectConfig = data;
                    record.isSelectConfig = true
                }

            });
        },
        clearSelectConfig(record){
            this.$confirm({
                title: this.$ti18('rxMsa.tipsInfo','提示信息'),
                content: this.i18n2('sureDelete','确认删除配置吗?'),
                onOk() {
                    record.selectConfig="";
                    record.isSelectConfig=false;
                },
                onCancel() {},
                okText:this.$ti18('rxForm.ackBtn','确认'),
                cancelText:this.$ti18('rxForm.cancelBtn','取消')
            });
        },
        /**
         * 清楚按钮条件配置
         * @param record
         */
        clearBtnShowCondition(record){
            let self_=this;
            this.$confirm({
                title: self_.$ti18('rxMsa.tipsInfo','提示信息'),
                content: self_.i18n2('sureDelete','确认删除配置吗?'),
                onOk() {
                    record.btnShow="";
                    record.isSetedShowCondition=false;
                },
                onCancel() {},
                okText:this.$ti18('rxForm.ackBtn','确认'),
                cancelText:this.$ti18('rxForm.cancelBtn','取消')
            });
        },
        /**
         * 清除按钮点击条件。
         * @param record
         */
        clearPreCondition(record){
            let self_=this;
            this.$confirm({
                title: self_.$ti18('rxMsa.tipsInfo','提示信息'),
                content: self_.i18n2('sureDelete','确认删除配置吗?'),
                onOk() {
                    record.btnPreCond="";
                    record.isSetedPreCondition=false;
                },
                onCancel() {},
                okText:this.$ti18('rxForm.ackBtn','确认'),
                cancelText:this.$ti18('rxForm.cancelBtn','取消')
            });
        },
        /**
         * 清除按钮点击条件。
         * @param record
         */
        clearBtnConfig(record){
            let self_=this;
            this.$confirm({
                title: self_.$ti18('rxMsa.tipsInfo','提示信息'),
                content: self_.i18n2('sureDelete','确认删除配置吗?'),
                onOk() {
                    record.config={};
                    record.isSetedBtn=false;
                },
                onCancel() {},
                okText:this.$ti18('rxForm.ackBtn','确认'),
                cancelText:this.$ti18('rxForm.cancelBtn','取消')
            });
        },
        renderTypeChange(value,record){
            let isConfig = true;
            let j =0
            this.headerFields.map(res=>{
                if(res.renderType=='ACTION'){j++}
            })
            if(j>1){this.$message.warning(this.i18n2('renderType','请勿选择2个操作列'));  record.renderType=""; return}
            for (var i = 0; i < this.cololumRenderTypes.length; i++) {
                if (this.cololumRenderTypes[i].value == value) {
                    isConfig = this.cololumRenderTypes[i].isConfig;
                    if(value=='ACTION'){
                        record['header']=this.cololumRenderTypes[i].label;
                        record.field="ACTION";
                        record.headerAlign="left";
                        record.fixed="false";
                    }
                    break;
                }
            }
            if (!isConfig) {
                record.isShowNotRender = true
            }else{
                record.isShowNotRender = false
                record.isSetedRender = false;
            }
            record.renderConf="";
            record.linkConf="";
        },

        openTabTree(text,record){
            let self =this;
            DialogBox.openTreeList({
                curVm: this, widthHeight: ['800px', '600px'],
                data:{isDialog:'YES',isTreeDlg:'YES'},
            },function(self,data){
                var obj=data[0];
                record.tabName=obj.key;
                record.tabName_name=obj.name;
                record.treeId=obj.name;
                record.isLazy=obj.isLazy;
                record.onlySelLeaf=obj.onlySelLeaf;
                record.onnodeclick="onTree_"+obj.key;
                self.getFormBoListInfo(obj.id,record);
            })
        },
        getFormBoListInfo(id,record){
            FormBoListApi.get(id).then(res =>{
                if(!res.success || !res.data.extJson){
                    return;
                }
                let extJson = JSON.parse(res.data.extJson);
                record.idField=extJson.idField;
                record.textField=extJson.textField;
                record.parentField=extJson.parentField;
            });
        },
        fcChange(value,record){
            if(value=="user" || value=="group"){
                record.fieldOp="IN";
            }else if(value=="numberrange"){
                record.fieldOp="";
            }
        },
        selectGroupNodeFun(selKeys,record,fieldLabel,close){
            if(!selKeys){
                return;
            }
            this.fieldFocus(record);
            record.fieldName=selKeys;
            this.changeFieldName(selKeys,record,fieldLabel);
            close();
        },
        //搜索条件表格方法
        addSearchRow() {
            this.addRow({fc: 'textbox', type: 'query', fieldName:'', autoFilter: 'YES', fieldOp: 'EQ'})
        },
        addSearchSplit() {
            this.addRow({fieldName: '-', fieldLabel: '-', fieldOp: '-', fc: '-'})
        },
        /*
        清除配置的数据
         */
        fcCleanUp(record){
            //默认要保留的数据
            let name = ['autoFilter','dataType','dataType_name','fc','fieldLabel','fieldName','fieldOp','i18nConf','idx_','searchSetting','serial','tablePre','type']
            for(let row in record){
                if(!name.contains(row)){
                    delete record[row]
                }
            }
        },
        showSearchConfigEditor(event,record,table) {
            if(!table){
                table = this.$refs["table_" + this.activeKey];
            }
            var row = record//table.getSelectedRow();
            if (!row || row.fc == "-") {
                this.$message.error(this.i18n2('notEmpty','搜索控件列不能为空'));
                return false;
            }
            var aryType=this.fieldControls.filter(item=>{
                return row.fc==item.value;
            })
            var wh=aryType[0].widthHeight;
            var conf = {
                component: MiniQuery,
                title: this.i18n2('searchConfig','搜索条件配置'),
                curVm: this,
                data: {row: row, fieldDatas: this.fieldDatas,queryAry:table.getData(),showDefault:true},
                // widthHeight: ['800px', '400px']
                widthHeight: wh,
                shade:true
            };
            Util.open(conf, function (action) {
                if (action != 'ok') {
                    return;
                }
                var data = this.getData();
                row.isSeted = true;
                table.updateRow(row,data);
                table.$forceUpdate();
            });
        },
        showSearchGroupViewConfig(record){
            var table = this.$refs["table_"+this.activeKey];
            var row = record;
            if (!row || !row.fieldName) {
                this.$message.error(this.i18n2('noEmpty','分组字段不能为空'));
                return false;
            }
            var conf = {
                component: FormBoListSearchGroup,
                title: this.i18n2('fieldConfig','分组字段配置'),
                curVm: this,
                data: {row: row,fieldDatas: this.fieldDataAll},
                widthHeight: ['800px', '600px']
            };
            Util.open(conf, function (action) {
                if (action != 'ok') {
                    return;
                }
                var data = this.getData();
                row.isSeted = true;
                table.updateRow(row,data);
                table.$forceUpdate();
            });
        },
        showSearchViewConfig(record){
            var table = this.$refs["table_"+this.activeKey];
            var row = record//table.getSelectedRow();
            if (!row || row.fc == "-") {
                this.$message.error(this.i18n2('notEmpty','搜索控件列不能为空'));
                return false;
            }
            var conf = {
                component: MiniQuery,
                title: this.i18n2('searchConfig','搜索条件配置'),
                curVm: this,
                data: {row: row, fieldDatas: this.fieldDataAll,queryAry:table.getData(),showDefault:false,showRelation:true},
                widthHeight: ['1200px', '600px']
            };
            Util.open(conf, function (action) {
                if (action != 'ok') {
                    return;
                }
                var data = this.getData();
                row.isSeted = true;
                table.updateRow(row,data);
                table.$forceUpdate();
            });
        },
        addColumnRow(){
            this.addRow({header:'',allowSort:false,width:100,format:'',
                url:'',linkType:'', field:'',dataType:'',control:'',
                headerAlign:'', fixed:'',renderType:'',rowMerge:false})
        },
        addButtonRow(){
            var data=this.$refs["table_" + this.activeKey].getData();
            var maxId=100;
            for(var i=0;i<data.length;i++){
                if(maxId<data[i].toolId){
                    maxId=data[i].toolId;
                }
            }
            this.addRow({idx_:Util.randomId(),toolId:maxId+1,toolPid:0,btnLabel:'',btnStyle:'default',btnType:'listMethod',btnName:'',btnIcon:'',btnClick:'',config: '',needConfig: false,preDef:false})
        },
        addExcelExportRow(){
            this.addRow({id:Util.randomId(),isNew:true,name:"",isPublic:1,permission:{"label": this.i18n2('all',"所有人"), "value": "everyone"},dataList:this.mdl.key,setting:""});
        },
        addLeftTreeRow(){
            this.addRow({tabName:'',treeId:'',onnodeclick:'',paramName:'',idField:'',textField:'',parentField:''})
        },
        addSummaryRow(){
            this.addRow({pageSummary:false,fieldName:'',fieldLabel:'',type:'',format:'',suf:''})
        },
        changePcBtnType(row){
            let aryType = this.buttonType.filter(item => {
                return row.btnType == item.value;
            });
            if (aryType.length > 0) {
                let btnType = Util.deepClone(aryType[0]);
                row.btnLabel = btnType.label;
                row.btnName = this.mdl.key+"_"+btnType.value;
                row.btnType_name=btnType.label;
                row.btnClick="";
                delete btnType.label;
                delete btnType.value;
                delete row.config;
                delete row.needConfig;
                delete row.preDef;
                Object.assign(row, btnType);
            }
        },
        configExcelExport(row){
            var table = this.$refs["table_" + this.activeKey];
            DialogBox.openExportExcelDialog({
                curVm: this,
                data: {row:row,name:this.mdl.name,boListKey: this.mdl.key},
                widthHeight: ['1400px', '700px'],
            },function(action,data){
                if (action != 'ok') return;
                row.setting=data;
                row.isSetedBtn = true
                table.$forceUpdate();
            })
        },
        editRecord(record,index,type){
            DialogBox.openPermissionUser(this,record[type].value,function(self_,data){
                var rowData={};
                rowData[type] = data;
                self_.$refs["table_" + self_.activeKey].updateRow(record,rowData);
            },true);
        },
        configButton(row) {
            let type = row.btnType;
            let key = "func_" + type;
            if (!this[key]) {
                let msg = this.i18n2('pleaseDefFun1','请定义[') + `${key}` + this.i18n2('pleaseDefFun2',']方法')
                this.$message.warning(msg);
                return;
            }
            this[key](row);
        },
        func_scriptBtn(row){
            var self=this;
            if(!row.btnClick){
                self.showScript=true
                self.scriptRow=row;
                /*this.$layer.prompt({
                    title:self.i18n2('engLetters','必须为英文字母组合，如abcAction'),
                    area: ['500px','200px'],
                    btn: ['确定111', '取消1111'],
                },function (value) {
                    row.btnClick='on'+value;
                    self.$layer.close(this.id);
                    self.handScriptBtn(row);
                })*/
            }else{
                self.getHandScriptBtn(row);
            }
        },
        getHandScriptBtn(row){
            var table = this.$refs["table_" + this.activeKey];
            var conf = {
                component: FormBoListBtnServerScript,
                title: this.i18n2('scriptDef','按钮服务端响应脚本定义'),
                curVm: this,
                data: {row: row, fieldDatas: this.fieldDatas},
                widthHeight: ['1100px', '550px']
            };
            Util.open(conf, function (action) {
                if (action != 'ok') return;
                var serverHandleScript=this.getData();
                row.config = {serverHandleScript: serverHandleScript};
                row.isSetedBtn = true
                table.$forceUpdate()
            });
        },
        /**
         * 配置套打
         */
        func_printLodop(row) {
            var table = this.$refs["table_" + this.activeKey];
            if (!this.boDefId) {
                this.$message.warning(this.$ti18('rxForm.formName','请选择表单！','','select'));
                return;
            }
            var self = this;
            var config = {
                "curVm": self,
                "data": {
                    "formId": this.formId,
                    "formName": this.formName,
                    "boDefId": this.boDefId,
                    "allowEdit": false
                },
                component: FormPrintLodopList,
                title: this.i18n2('printTemp','套打模板') + "--" + this.formName,
                widthHeight: ['800px', '600px']
            };
            Util.open(config, function (action, data) {
                if (action != 'ok') return;
                row.config = {defId: data.pkId, name: data.name};
                row.isSetedBtn = true
                table.$forceUpdate()
            });
        },
        /**
         * 配置pdf打印。
         **/
        func_pdfPrint(row) {
            var table = this.$refs["table_" + this.activeKey];
            var self = this;
            var config = {
                "curVm": self,
                "data": {
                    "formId": this.formId,
                    "formName": this.formName,
                    "boDefId": this.boDefId,
                    "allowEdit": false
                },
                component: FormPdfTemplateList,
                title: this.i18n2('pdfPrint','PDF打印') + this.formName,
                widthHeight: ['800px', '600px']
            };
            Util.open(config, function (action, data) {
                if (action != 'ok') return;
                row.config = {defId: data.pkId, name: data.name};
                row.isSetedBtn = true
                table.$forceUpdate()
            });
        },
        /**
         * 配置打开单据转换
         * @param row
         */
        func_formTran(row){
            var table = this.$refs["table_" + this.activeKey];
            let config = "";
            if (row && row.config){
                config = JSON.stringify(row.config);
            }
            var conf = {
                curVm: this,
                data: {
                    pkId:this.pkId,
                    "boDefId": this.boDefId,
                    formTranConfigStr:config
                },
                widthHeight: ['800px', '500px'],
                component: FormBoListConfigFormTranDialog,
                title: this.i18n2('formTran',"单据转换")

            };
            Util.open(conf, function (action, data) {
                if (action != 'ok') return;
                row.config = data;
                table.$forceUpdate()
            })
        },
        /**
         * 配置打开表单
         */
        func_openCustomForm(row) {
            var table = this.$refs["table_" + this.activeKey];
            let config = row.config;

            var conf = {
                curVm: this,
                data: {pkId:this.pkId,formConfig: config.formConfig},
                widthHeight: ['800px', '600px'],
                component: FormBoListConfigOpenFormDialog,
                title: this.i18n2('openFormConfig','打开表单配置')

            };
            Util.open(conf, function (action, data) {
                if (action != 'ok') return;
                row.formAlias = data.formAlias;
                row.formName = data.formName;
                row.boDefId = data.boDefId;
                row.config.formConfig = JSON.stringify(data);
                row.isSetedBtn = true
                table.$forceUpdate()
            })
        },
        func_openCustomList(row){
            var table = this.$refs["table_" + this.activeKey];
            let config = row.config;
            var conf = {
                curVm: this,
                data: {conf:config.listConfig,fieldDts: this.fieldDatas},
                widthHeight: ['800px', '600px'],
                component: FormBoListConfigOpenListDialog,
                title: this.i18n2('listConfig','打开列表配置')

            };
            Util.open(conf, function (action, data) {
                if (action != 'ok') return;
                row.config.listConfig = JSON.stringify(data);
                row.isSetedBtn = true
                table.$forceUpdate()
            })
        },
        /**
         * 配置UReport报表。
         */
        func_ureportPrint(row) {
            var table = this.$refs["table_" + this.activeKey];
            var self = this;
            let conf = row.config;
            if (row.config.params==null){
                config.params=[];
            }
            var config = {
                "curVm": self,
                "data": {
                    "allowEdit": false,
                    pkId:self.pkId,
                    customConfig: conf
                },
                component: FormListOpenUreportDialog,
                title: self.i18n2('reportPrint','报表打印') + self.formName,
                widthHeight: ['800px', '600px']
            };
            Util.open(config, function (action, data) {
                if (action != 'ok') return;
                //row.config = {defId: data.pkId, name: data.name,params:data.params};
                row.config = data;
                row.isSetedBtn = true
                table.$forceUpdate()
            });
        },
        func_openCustomView(row){
            var table = this.$refs["table_" + this.activeKey];
            let config = row.config;
            var conf = {
                curVm: this,
                data: {pkId:this.pkId,customConfig: config},
                widthHeight: ['800px', '600px'],
                component: FormListOpenCustomDialog,
                title: this.i18n2('pageConfig','打开页面定制配置')

            };
            Util.open(conf, function (action, data) {
                if (action != 'ok') return;
                row.alias = data.alias;
                row.name = data.name;
                row.config = data;
                row.isSetedBtn = true
                table.$forceUpdate()
            })
        },
        //配置word打印
        func_wordPrint(row) {
            var self = this;
            var config = {
                "curVm": self,
                data: {
                    "boDefId": this.boDefId,
                    "templateId": row.config.templateId
                },
                component: FormWordTemplateDialog,
                title: this.i18n2('selectWordTemp','选择word模板'),
                widthHeight: ['800px', '600px']
            };
            Util.open(config, function (action, data) {
                if (action != 'ok') return;
                row.config = {templateId: data.pkId,boDefId:self.boDefId};

            });
        },
        func_pdfDownload(row) {
            var self = this;
            var config = {
                "curVm": self,
                data: {
                    "boDefId": this.boDefId,
                    "templateId": row.config.templateId
                },
                component: FormWordTemplateDialog,
                title: this.i18n2('selectWordTemp','选择word模板'),
                widthHeight: ['800px', '600px']
            };
            Util.open(config, function (action, data) {
                if (action != 'ok') return;
                row.config = {templateId: data.pkId,boDefId:self.boDefId};

            });
        },
        func_openPdf(row) {
            var self = this;
            var config = {
                "curVm": self,
                data: {
                    "boDefId": this.boDefId,
                    "templateId": row.config.templateId
                },
                component: FormWordTemplateDialog,
                title: this.i18n2('selectWordTemp','选择word模板'),
                widthHeight: ['800px', '600px']
            };
            Util.open(config, function (action, data) {
                if (action != 'ok') return;
                row.config = {templateId: data.pkId,boDefId:self.boDefId};

            });
        },
        func_listMethod(row){
            var self = this;
            var config = {
                "curVm": self,
                data: {
                    "config": row.config
                },
                component: ListMethodDialog,
                title: this.i18n3('list.listMethod','列表按钮配置'),
                widthHeight: ['600px', '400px']
            };
            Util.open(config, function (action, data) {
                if (action != 'ok') return;
                row.config = data;
            });
        },
        //配置规则引擎
        func_handleLiteFlow(row) {
            var self=this;
            var config = {
                "curVm": self,
                data: {
                    "liteFlowId":row.config.liteFlowId
                },
                component: FormLiteFlowDialog,
                title: this.i18n2('handleLiteFlow',"规则引擎"),
                widthHeight: ['900px', '700px']
            };
            Util.open(config, function (action, data) {
                if (action != 'ok') return;
                row.config = {liteFlowId: data.pkId,liteFlowName:data.chainDesc};
            });
        },
        //自定义页面
        func_customPage(row){
            let obj = {
                curVm:this,
                component:CustomControlDialog,
                title: this.i18n2('openCustomControl','打开自定义组件配置'),
                widthHeight: ['800px', '500px'],
                data:{
                    openConfig:row.config
                }
            }
            Util.open(obj, function (action, data) {
                if (action != 'ok') return;
                row.config = data
            });
        },
        initBtns(values){
            var key=values.key;
            this.btns=[{toolId:1,toolPid:0,btnLabel:this.$ti18('rxList.add', '新增'),btnStyle:'primary',btnType:'listMethod',btnName:key+'_Add',btnIcon:'{"type":"jpaasIcon","icon":"iconcommon-add"}', btnClick:'onAdd',config: {isMax:"YES",height:600,width:800},needConfig: true,preDef:true},
                {toolId:3,toolPid:0,btnLabel:this.$ti18('rxList.delBtn','删除'),btnStyle:'default',btnType:'listMethod',btnName:key+'_Remove',btnIcon:'{"type":"jpaasIcon","icon":"iconVue3_delete"}',btnClick:'onRemove',config: '',needConfig: false,preDef:true},
                {toolId:6,toolPid:0,btnLabel:this.$ti18('rxList.refreshBtn','刷新'),btnStyle:'default',btnType:'listMethod',btnName:key+'_Refresh',btnIcon:'{"type":"jpaasIcon","icon":"iconVue3_reset"}',btnClick:'onRefresh',config: '',needConfig: false,preDef:true},
                {toolId:14,toolPid:0,btnLabel:this.i18n2('printCode','打印二维码'),btnStyle:'default',btnType:'listMethod',btnName:key+'_PrintQrCode',btnIcon:'{"type":"jpaasIcon","icon":"iconorder"}',btnClick:'onPrintQrCode',config: '',needConfig: false,preDef:true},
                {toolId:8,toolPid:0,btnLabel:this.i18n2('exportExcel','导出EXCEL'),btnStyle:'default',btnType:'listMethod',btnName:key+'_Export',btnIcon:'{"type":"jpaasIcon","icon":"icondaochu"}',btnClick:'onXLSExportShow',config: '',needConfig: false,preDef:true},
                {toolId:9,toolPid:0,btnLabel:this.$ti18('rxList.importBtn','导入'),btnStyle:'default',btnType:'listMethod',btnName:key+'_Import',btnIcon:'{"type":"jpaasIcon","icon":"icondaoru"}',btnClick:'onImport',config: '',needConfig: false,preDef:true},
                {toolId:15,toolPid:0,btnLabel:this.i18n2('exportTem','配置导出模板'),btnStyle:'default',btnType:'listMethod',btnName:key+'_ExportConfig',btnIcon:'{"type":"jpaasIcon","icon":"iconsend"}',btnClick:'onXLSExport',config: '',needConfig: false,preDef:true},
                {toolId:16,toolPid:0,btnLabel:this.i18n2('fullScreen','全屏'),btnStyle:'default',btnType:'listMethod',btnName:key+'_fullScreen',btnIcon:'{"type":"jpaasIcon","icon":"iconmodal-fullscreen"}',btnClick:'toggleFullScreen',config: '',needConfig: false,preDef:true}]
            if(values.rowEdit=='YES'){
                this.btns.splice(2,0,{toolId:7,toolPid:0,btnLabel:this.$ti18('rxForm.saveBtn','保存'),btnStyle:'default',btnType:'listMethod',btnName:key+'_Save',btnIcon:'{"type":"jpaasIcon","icon":"iconVue3jpaas-icon_baocun"}',btnClick:'onRowsSave',config: '',needConfig: false,preDef:true});
                let excludBtnName = [key+"_Edit",key+"_Detail"]
                if (this.parentVm.initButtons.length > 0){
                    this.parentVm.initButtons = this.parentVm.initButtons.filter(btn => !excludBtnName.contains(btn.btnName));
                    this.parentVm.initButtons.splice(0,0,{toolId:7,toolPid:0,btnLabel:this.$ti18('rxForm.saveBtn','保存'),btnStyle:'default',btnType:'listMethod',btnName:key+'_Save',btnIcon:'{"type":"jpaasIcon","icon":"iconVue3jpaas-icon_baocun"}',btnClick:'onRowsSave',config: '',needConfig: false,preDef:true});
                }
            }else{
                this.btns.splice(1,0,{toolId:2,toolPid:0,btnLabel:this.$ti18('rxList.editBtn','编辑'),btnStyle:'default',btnType:'listMethod',btnName:key+'_Edit',btnIcon:'{"type":"jpaasIcon","icon":"iconbrush"}',btnClick:'onEdit',config:  {isMax:"YES",height:600,width:800},needConfig: true,preDef:true});
                this.btns.splice(3,0,{toolId:4,toolPid:0,btnLabel:this.$ti18('rxList.detailBtn','明细'),btnStyle:'default',btnType:'listMethod',btnName:key+'_Detail',btnIcon:'{"type":"jpaasIcon","icon":"iconmore1"}',btnClick:'onDetail',config: {isMax:"YES",height:600,width:800},needConfig: true,preDef:true});
            }
            if(values.dataStyle=='tree'){
                var extBtns=[{toolId:10,toolPid:0,btnLabel:this.$ti18('rxList.putAwayBtn','收起'),btnStyle:'default',btnType:'listMethod',btnName:key+'_Collapse',btnIcon:'{"type":"jpaasIcon","icon":"iconicon-test38"}',btnClick:'onCollapse',config:  {isMax:"YES",height:600,width:800},needConfig: true,preDef:true},
                    {toolId:11,toolPid:0,btnLabel:this.$ti18("rxList.openBtn","展开"),btnStyle:'default',btnType:'listMethod',btnName:key+'_Expand',btnIcon:'{"type":"jpaasIcon","icon":"iconicon-test40"}',btnClick:'onExpand',config: '',needConfig: false,preDef:true},
                    {toolId:12,toolPid:0,btnLabel:this.i18n2('addRecord','新增子记录'),btnStyle:'default',btnType:'listMethod',btnName:key+'_AddSub',btnIcon:'{"type":"jpaasIcon","icon":"iconcommon-add"}',btnClick:'onAddSub',config: {isMax:"YES",height:600,width:800},needConfig: true,preDef:true}
                ];
                for(var i=0;i<extBtns.length;i++){
                    this.btns.splice(2,0,extBtns[i]);
                }
            }
            // 满足条件添加默认按钮
            if (this.toolBarFields.length == 0 && this.parentVm.initButtons.length > 0){
                this.toolBarFields = this.parentVm.initButtons;
            }
        },
        addToolbarAllRows(){
            let btnsTree= Util.listToTree(this.btns,'toolId','toolPid');
            for(let i=0;i<btnsTree.length;i++){
                let tmpBtns=this.toolBarFields.filter(item=>{
                    return btnsTree[i].toolId==item.toolId;
                });
                if(tmpBtns.length>0){
                    continue;
                }
                let btn= btnsTree[i];
                btn.idx_=Util.randomId();
                this.loadInitI18nVal(btn,'btnLabel');
                this.setOtherDefaultI18nVal(btn);
                this.toolBarFields.push(btn);
            }
            //this.toolBarFields=Util.listToTrecurAppObje(this.btns,'toolId','toolPid');
        },
        loadInitI18nVal(obj,text){
            if(!obj.i18nJson){
                let i18nJson = {};
                i18nJson[this.i18nCurrent]=obj[text];
                obj.i18nJson=JSON.stringify(i18nJson);
                return;
            }
            let i18nJson =JSON.parse(obj.i18nJson);
            let val=i18nJson[this.i18nCurrent];
            if(!val){
                return;
            }
            obj[text]=val;
        },
        //设置中文、英文默认值
        setOtherDefaultI18nVal(btn){
            let langs=I18Parse.handleLanList();
            if(!langs || langs.length==0){
                return;
            }
            let self_=this;
            langs.forEach(lang=>{
                if(lang!=this.i18nCurrent){
                    let langVal=self_.defaultBtnI18ns[btn.btnClick];
                    if(langVal){
                        let i18nJson= JSON.parse(btn.i18nJson);
                        i18nJson[lang]=langVal[lang];
                        btn.i18nJson=JSON.stringify(i18nJson);
                    }
                }
            })

        },

        //返回字段表格方法
        checkAllFields(e,field) {
            var table = this.$refs["table_" + this.activeKey];
            var checked = e.target.checked;
            var data = table.getData();
            for (var i = 0; i < data.length; i++) {
                var row = data[i];
                let obj={};
                obj[field]=checked;
                table.updateRow(row, obj);
            }
        },
        changeFieldName(value,record,header){
            record.i18nConf={};
            if(record["searchField"] && record["searchField"].change){
                record["searchField"].change=false;
                value=record["searchField"];
                if(header) {
                    record[header] = value;
                }
            }
            var flag=false;
            for(var i=0;i<this.fieldDatas.length;i++){
                if(this.fieldDatas[i].value==value){
                    record.dataType=this.fieldDatas[i].key;
                    record.dataType_name=this.getDataTypeName(record.dataType);
                    if(header) {
                        record[header] = this.fieldDatas[i].label;
                    }
                    flag=true;
                    break;
                }
            }
            if(!flag){
                record.dataType='string';
                record.dataType_name=this.i18n2('character','字符');
            }
        },
        getDataTypeName(dataType) {
            let json={'string':this.i18n2('character','字符'),'int':this.i18n2('integer','整型'),'number':this.i18n2('float','浮点型'),'date':this.i18n2('dateType','日期型'),'boolean':this.i18n2('boolean','布尔型'),'currency':this.i18n2('moneyType','货币型')};
            if(json[dataType]){
                return json[dataType];
            }
            return '';

        },
        onSelectSearchChange(selectedRowKeys, selectedRow) {
            this.selectedSearchRowKeys = selectedRowKeys;
            this.selectedSearchRows = selectedRow;
        },
        onSelectGrantChange(selectedRowKeys, selectedRow) {
            this.selectedGrantRowKeys = selectedRowKeys;
        },

        openScriptQuery(text, record) {
            Dialog.openScripttextDialog({
                curVm: this, widthHeight: ['1200px', '600px'], data: {
                    script: text,
                    scriptInsertAry:scriptLib
                }
            }, function (self, data) {
                record.value = data;
            })
        },
        iconChange(icon,record){
            delete record['btnIcon_name'];
            if(icon){
                let iconJson=JSON.parse(icon);
                record['btnIcon_name']=iconJson.icon;
            }
        },
        addPublishRow() {
            this.addRow({
                field: '', fieldName: ''
            })
        },
        getColumnRender(type){
            var ary=this.cololumRenderTypes;
            for(var i=0;i<ary.length;i++){
                var o=ary[i];
                if(o.value==type){
                    return o;
                }
            }
            return null;
        },
        getFields() {
            if(!this.pkId){
                return;
            }
            this.allFields = [];
            FormBoListApi.reloadColumns(this.pkId).then(res => {
                for (var i = 0; i < res.data.length; i++) {
                    var newRow = {
                        label: res.data[i].header,
                        value: res.data[i].field,
                        key: res.data[i].dataType
                    }
                    this.allFields.push(newRow);
                }
            });
        },
        //机构列头个性化
        instCustomization(){
            if(!this.headerFields || this.headerFields.length==0){
                this.$message.error(this.i18n2('configHeader','请先配置列头!'));
                return;
            }
            var listColumns=[];
            for (let i = 0; i < this.headerFields.length; i++) {
                listColumns.push({
                    value:this.headerFields[i].field,
                    label:this.headerFields[i].header
                })
            }
            var self=this;
            Util.open({
                component:InstColumn,
                curVm:this,
                widthHeight: ['1000px', '600px'],
                title: this.i18n2('colHeads','机构列头个性化'),
                data:{
                    listColumns:listColumns,
                    instColumnConfig:self.instColumnConfig
                }
            },function (action,data){
                if(action!='ok') return;
                self.instColumnConfig=data;
            });
        },
        showInsertScript(item){
            let script=item.condition;
            if(!script){
                return true;
            }
            script ="return " +script ;
            let fn=new Function("mdl",script);
            let rtn=fn(this.mdl);
            return rtn;
        },

        showLinkConfig(record){
            if(!record.renderType){
                return false;
            }
            let obj=this.getColumnRender(record.renderType);
            if(obj.supportLink){
                return true;
            }
            return false;
        },
        linkSetting(record){
            var renderConf=record.linkConf || {type:"form",setting:{},model:false,isMax:"YES",height:800,width:600};
            var wh= ['800px', '600px'];
            let self =this;
            var conf = {
                component: renderConfig_link,
                title: this.i18n2('configLink','配置链接'),
                curVm: this,
                data: {config: renderConf, fields: this.fieldDatas,listId:this.pkId,dialog:true},
                widthHeight: wh,
                shade:true
            };
            Util.open(conf, function (action) {
                    if (action != 'ok') {
                        return;
                    }
                    let data=this.getData();
                    record.linkConf=data;
                    self.$forceUpdate();
                }
            );

        },
        selectDataSource(){
            let self_=this;
            Dialog.openDataSourceDialog({
                curVm: this, widthHeight: ['1200px', '600px'],
                data:{appName:JsConstant.JPAAS_LOWCODE}
            }, function (self, data) {

                self_.insertImportScript('"'+data.alias+'"');
            })
        },
        showScriptDialog(){
            let self=this;
            let config={curVm:this};
            Dialog.openScriptDialog(config,function (script){
                self.$refs.javaCode.insertContent(script);
            })
        },
    },
    data() {
        return {
            confirmLoading:false,
            i18nDefault:process.env.VUE_APP_LANGUAGE,
            i18nCurrent:"",
            listLayout: {
                openBoard: {name: ApiFormCoreLang.apiFormCore.kanbanView, status: false, config: ""}
            },
            ScriptInsertAry:ScriptInsertAry,
            activeKey: "columnConf",
            webActiveKey: "header",
            interfaceActiveKey: "query",
            webColumns: [
                {title: this.i18n2('paramName','参数名'), dataIndex: 'key', width: 100},
                {title: this.i18n2('illustrate','说明'), dataIndex: 'description', width: 100},
                {
                    title: this.$comi18('formDef.valueSource', '值来源'),
                    dataIndex: 'valueSource',
                    width: 100,
                    scopedSlots: {customRender: 'valueSource'}
                },
                {title: this.i18n2('defValue','默认值'), dataIndex: 'value', width: 100, scopedSlots: {customRender: 'value'}}
            ],
            webHeaderFields: [],
            webParamsFields: [],
            interfaceFields:[],
            listHtml: "",
            icon: 'smile',
            constantField: [],
            isLeftTree: 'NO',
            showSummaryRow:'NO',
            isExpandRow: 'NO',
            expandedRowKeys: [],
            fieldDatas: [],
            rowControls: [{value: '',label: ''},
                {value: 'input', label: this.i18n2('lineText','单行文本'), tag: 'a-input'},
                {value: 'textarea', label: this.i18n2('multiline','多行文本'), tag: 'a-textarea'},
                {value: 'inputNumber', label: this.i18n2('numInputBox','数字输入'), tag: 'a-input-number'},
                {value: 'checkbox', label:this.i18n2('checkBox','复选框'), tag: 'a-checkbox'},
                {value: 'datePicker', label: this.i18n2('date','日期'), tag: 'a-date-picker'},
                {value: 'select', label: this.i18n2('dropSelect','下拉选择'), tag: 'a-select'},
                {value: 'dialog', label: this.i18n2('customDialog','自定义对话框'),tag: 'rx-input-button'}],
            cololumRenderTypes:cololumRenderTypeList,
            fieldControls: [
                // {label: this.i18n2('textBox','文本框'), value: 'textbox'},
                {title:this.i18n2('textBox','文本框'),value: 'textbox', widthHeight:['800px', '300px']},
                {label: this.i18n2('date','日期'), value: 'datepicker',widthHeight:['800px', '400px']},
                {label: this.i18n2('dateRange','日期范围'), value: 'rangepicker',widthHeight:['800px', '450px']},
                {label: this.i18n2('month','月份'), value: 'month',widthHeight:['800px', '500px']},
                {label: this.i18n2('dropDownBox','下拉框'), value: 'select',widthHeight:['850px', '750px']},
                {label: this.i18n2('treeBox','树形下拉框'),value:'treeselect',widthHeight:['800px', '770px']},
                {label: this.i18n2('customDialog','自定义对话框'), value: 'dialog',widthHeight:['850px', '750px']},
                {label: this.i18n2('numBox','数字框'), value: 'number',widthHeight:['750px', '300px']},
                {label: this.i18n2('numRange','数字范围'), value: 'numberrange',widthHeight:['750px', '300px']},
                {label: this.i18n2('user','用户'), value: 'user',widthHeight:['750px', '400px']},
                {label: this.i18n2('department','部门'), value: 'group',widthHeight:['750px', '400px']},
                {label: this.i18n2('checkBox','复选框'), value: 'checkboxgroup',widthHeight:['800px', '750px']}

            ],
            headerFields: [],
            headerColumns: [
                {title: this.i18n2('name','字段名称'), dataIndex: 'header', scopedSlots: {customRender: 'header'},width:180},
                {title: this.i18n2('key','字段Key'), dataIndex: 'field', scopedSlots: {customRender: 'field'},width:180},
                {title: this.i18n2('sortable','可排序'), dataIndex: 'allowSort', type: 'checkboxColumn', scopedSlots: {customRender: 'allowSort'},width:60,align:'center'},
                {slots: { title: 'customRowMergeTitle' }, dataIndex: 'rowMerge', scopedSlots: {customRender: 'rowMerge'},width:60,align:'center'},
                {slots: { title: 'customTitle' }, dataIndex: 'width', scopedSlots: {customRender: 'width'},width:100},
                {
                    title: this.i18n2('dataType','数据类型'),
                    dataIndex: 'dataType',
                    scopedSlots: {customRender: 'dataType'},
                    width:90
                },
                {
                    title: this.i18n2('TextPosition','文本位置'),
                    dataIndex: 'headerAlign',
                    scopedSlots: {customRender: 'headerAlign'},
                    width:80
                },
                {
                    title: this.i18n2('lockPosition','锁定位置'),
                    dataIndex: 'fixed',
                    scopedSlots: {customRender: 'fixed'},
                    width:90
                },
                {title: this.i18n2('fieldCtl','字段控件'), dataIndex: 'control',scopedSlots: {customRender: 'control'},width:120},
                {
                    title: this.i18n2('renderMethod','渲染方式'),
                    dataIndex: 'renderType',
                    scopedSlots: {customRender: 'renderType'},
                    width:120
                },{
                    title: this.i18n2('fieldRender','字段渲染'),
                    dataIndex: 'renderField',
                    scopedSlots: {customRender: 'renderField'},
                    width:200
                },{
                    title: this.i18n2('filterConfig','过滤配置'),
                    dataIndex: 'filterConfig',
                    scopedSlots: {customRender: 'filterConfig'},
                    width:120
                }],
            expandRowFields:[],
            leftTreeFields: [],
            leftTreeColumns: [
                {title: this.i18n2('selectTabName','选择树'),width:100, dataIndex: 'tabName', scopedSlots: {customRender: 'tabName'}},
                {title: this.i18n2('tabName','导航Tab名称'),width:100, dataIndex: 'treeId', scopedSlots: {customRender: 'treeId'}},
                {title: this.i18n2('clickEvent','点击事件'),width:100, dataIndex: 'onnodeclick', scopedSlots: {customRender: 'onnodeclick'}},
                {title: this.i18n2('paramName','参数名称'),width:100, dataIndex: 'paramName', scopedSlots: {customRender: 'paramName'}},
                {title: this.i18n2('valueField','值字段'),width:100, dataIndex: 'idField'},
                {title: this.i18n2('showFiled','显示字段'),width:100, dataIndex: 'textField'},
                {title: this.i18n2('parentField','父ID字段'),width:100, dataIndex: 'parentField'},
                {title: this.i18n2('leafNode','仅选择叶子节点'),width:100, dataIndex: 'onlySelLeaf',scopedSlots: {customRender: 'onlySelLeaf'}},
            ],
            summaryPageName:"",
            //新统计行数据
            statisticsRows:[],
            //是否有旧数据
            isOldCalcData:false,
            searchFields: [],
            selectedSearchRowKeys: [],
            selectedSearchRows: [],
            searchColumns: [{
                title: this.i18n2('paramType','参数类型'),
                dataIndex: 'type',
                scopedSlots: {customRender: 'type'},
                width:120
            },
                {title: this.i18n2('prefix','表前缀'), dataIndex: 'tablePre', scopedSlots: {customRender: 'tablePre'}, width:120},
                {
                    title: this.i18n2('searchField','搜索字段'),
                    dataIndex: 'fieldName',
                    scopedSlots: {customRender: 'fieldName'},
                    width:120,
                    customCell:(record,rowIndex)=>{if(record){ return {class:'noOverflow'}}}
                },
                {title: this.i18n2('label','标签'), dataIndex: 'fieldLabel', scopedSlots: {customRender: 'fieldLabel'}, width:120},
                {
                    title: this.i18n2('autoFilter','自动过滤'),
                    dataIndex: 'autoFilter',
                    scopedSlots: {customRender: 'autoFilter'},
                    width:120
                },
                {
                    title: this.i18n2('comparator','比较符'),
                    dataIndex: 'fieldOp',
                    scopedSlots: {customRender: 'fieldOp'},
                    width:120
                },
                {
                    title: this.i18n2('inputCtl','输入控件'),
                    dataIndex: 'fc',
                    scopedSlots: {customRender: 'fc'},
                    width:120
                },
                {
                    title: this.i18n2('searchConf','搜索配置'),
                    dataIndex: 'searchSetting',
                    scopedSlots: {customRender: 'searchSetting'},
                    width:120
                }],
            selectedGrantRowKeys: [],
            buttonType: [
                {label: this.i18n2('scriptBtn','脚本按钮'), value: "scriptBtn", btnClick: "", needConfig: true, preDef: false, config: {serverHandleScript:""}},
                {label: this.i18n2('nestPrint','套打'), value: "printLodop", btnClick: "printLodop", needConfig: true, preDef: true, config: {defId: "", name: ""}},
                {label: this.i18n2('pdfPrint','PDF打印'), value: "pdfPrint", btnClick: "pdfPrint", config: {defId: "", name: ""}, needConfig: true, preDef: true},
                {label: this.i18n2('report','报表'), value: "ureportPrint", btnClick: "ureportPrint", config: {alias: "", name: "",params:[],defId: ""}, needConfig: true, preDef: true},
                {label: this.i18n2('openForm','打开表单'), value: "openCustomForm", btnClick: "openCustomForm", needConfig: true, preDef: true, config: {formAlias: "", formName: "", formConfig: "", boDefId: ""}},
                {label: this.i18n2('OpenList','打开列表'), value: "openCustomList", btnClick: "openCustomList", needConfig: true, preDef: true, config: {boListId: "", name: "", alias: "", boList: "",listConfig:""}},
                {label: this.i18n2('listMethod','列表方法'), value: "listMethod", btnClick: "", needConfig: false, preDef: false},
                {label: this.i18n2('openCustomView','打开页面定制'), value: "openCustomView", btnClick: "openCustomView", needConfig: true, preDef: true, config: {alias: "", name: "",params:[],isMax:"YES",height:600,width:800}},
                {label: this.i18n2('wordPrint','Word打印'), value: "wordPrint", btnClick: "wordPrint", needConfig: true,config: {templateId: "",boDefId:""}, preDef: true},
                {label: this.i18n2('pdfDownload','下载PDF'), value: "pdfDownload", btnClick: "pdfDownload", needConfig: true,config: {templateId: "",boDefId:""}, preDef: true},
                {label: this.i18n2('openPDF','打开PDF'), value: "openPdf", btnClick: "openPdf", needConfig: true,config: {templateId: "",boDefId:""}, preDef: true},
                {label: this.i18n2('handleLiteFlow','规则引擎'), value: "handleLiteFlow", btnClick: "handleLiteFlow", needConfig: true,config: {liteFlowId:"",liteFlowName: ""}, preDef: true},
                {label: this.i18n2('formTran',"单据转换"), value: "formTran", btnClick: "formTran", needConfig: true,config: {boDefId:""}, preDef: true},
                {label: this.i18n2('customPage','自定义组件'), value: "customPage", btnClick: "customPage", needConfig: true,config: {title:'',path:'', width:'', height:'', callback:'',shade:false, model:true,isMax:'YES',preMethod:'', returnParameters:'',}, preDef: true}

            ],
            buttonStyle: [
                {value: 'primary', label: 'primary'},
                {value: 'default', label: 'default'},
                {value: 'dashed', label: 'dashed'},
                {value: 'danger', label: 'danger'},
                {value: 'link', label: 'link'}
            ],
            toolBarFields: [],
            toolBarColumns: [{
                title: this.i18n2('buttonName','按钮名称'),
                dataIndex: 'btnLabel',
                scopedSlots: {customRender: 'btnLabel'}
            },
                {title: this.i18n2('buttonMark','按钮标识'), dataIndex: 'btnName', scopedSlots: {customRender: 'btnName'}},
                {title: this.i18n2('buttonStyle','按钮样式'), dataIndex: 'btnStyle', scopedSlots: {customRender: 'btnStyle'}},
                {title: this.i18n2('typeButton','按钮类型'), dataIndex: 'btnType', scopedSlots: {customRender: 'btnType'}},
                {title: this.i18n2('eventFunc','事件函数'), dataIndex: 'btnClick', scopedSlots: {customRender: 'btnClick'}},
                {title: this.i18n2('buttonIcon','按钮图标'), dataIndex: 'btnIcon', scopedSlots: {customRender: 'btnIcon'}},
                {title: this.i18n2('buttonConfig','按钮配置'), dataIndex: 'config', scopedSlots: {customRender: 'config'}},
                {title: this.i18n2('displayCon','显示条件'), dataIndex: 'btnShow', scopedSlots: {customRender: 'btnShow'}},
                {title: this.i18n2('Preconditions','前置条件'), dataIndex: 'btnPreCond', scopedSlots: {customRender: 'btnPreCond'}}],
            btns: [],
            returnFields: [],
            returnAllFields: [],
            returnColumns: [
                {title: this.i18n2('name','字段名称'), dataIndex: 'header', scopedSlots: {customRender: 'header'}},
                {title: this.i18n2('key','字段Key'), dataIndex: 'field'},
                {title: this.i18n2('display','显示字段'), dataIndex: 'displayField',scopedSlots: {customRender: 'displayField'}}
            ],
            //发布
            publishFields: [],

            publishColumns: [{
                title: this.i18n2('field','字段'),
                dataIndex: 'field',
                scopedSlots: {customRender: 'field'},
                width:120
            },
                {
                    title: this.i18n2('name','字段名称'),
                    dataIndex: 'fieldName',
                    scopedSlots: {customRender: 'fieldName'},
                    width:120
                }

            ],
            headerColumnsExcel: [
                {dataIndex: 'sn', slots: {title: 'snTitle'}, scopedSlots: {customRender: 'sn'},width:120},
                {title: this.i18n2('excelName','Excel列头名称'), dataIndex: 'header', scopedSlots: {customRender: 'header'},width:120},
                {title: this.i18n2('dbField','对应数据库字段'), dataIndex: 'field', scopedSlots: {customRender: 'field'},width:120},
                {title: this.i18n2('dropDown','下拉框配置'), dataIndex: 'selectConfig', scopedSlots: {customRender: 'selectConfig'},width:120},
                {title: this.i18n2('required','是否必填'), dataIndex: 'required', type: 'checkboxColumn', scopedSlots: {customRender: 'required'},width:60}
            ],
            //所有字段
            allFields:[],
            //租户个性化列头
            instColumnConfig:[],
            excelExportFields:[],
            excelExportColumns:[
                {title: this.i18n2('configName','配置名称'), dataIndex: 'name', scopedSlots: {customRender: 'name'},width:120},
                {title: this.i18n2('config','配置'), dataIndex: 'setting', scopedSlots: {customRender: 'setting'},width:120},
                {title: this.i18n2('powerConfig','权限配置'), dataIndex: 'permission', scopedSlots: {customRender: 'permission'},width:120}
            ],
            scriptInsertAry:[


            ],
            opDataOptions:{
                'textbox':[
                    {label:this.i18n2('eq','等于'),value:'EQ'},
                    {label:this.i18n2('neq','不等于'),value:'NEQ'},
                    {label:this.i18n2('fuzzyQuery','模糊'),value:'LK'},
                    {label:this.i18n2('lek','左模糊'),value:'LEK'},
                    {label:this.i18n2('rik','右模糊'),value:'RIK'},
                    {label:this.i18n2('isEmpty','为空'),value:'ISNULL'},
                    {label:this.i18n2('isNotEmpty','不为空'),value:'NOTNULL'}
                ],
                'datepicker':[
                    {label:this.i18n2('eq','等于'),value:'EQ'},
                    {label:this.i18n2('neq','不等于'),value:'NEQ'},
                    {label:this.i18n2('lessThan','小于'),value:'LT'},
                    {label:this.i18n2('lessOrEqual','小于等于'),value:'LE'},
                    {label:this.i18n2('greater','大于'),value:'GT'},
                    {label:this.i18n2('greatOrEqual','大于等于'),value:'GE'},
                    {label:this.i18n2('isEmpty','为空'),value:'ISNULL'},
                    {label:this.i18n2('isNotEmpty','不为空'),value:'NOTNULL'}
                ],
                'rangepicker':[
                    {label:this.i18n2('include','包含'),value:'IN'},
                    {label:this.i18n2('notInclude','不包含'),value:'NIN'},
                    {label:this.i18n2('isEmpty','为空'),value:'ISNULL'},
                    {label:this.i18n2('isNotEmpty','不为空'),value:'NOTNULL'}
                ],
                'month':[
                    {label:this.i18n2('eq','等于'),value:'EQ'},
                    {label:this.i18n2('neq','不等于'),value:'NEQ'},
                    {label:this.i18n2('lessThan','小于'),value:'LT'},
                    {label:this.i18n2('lessOrEqual','小于等于'),value:'LE'},
                    {label:this.i18n2('greater','大于'),value:'GT'},
                    {label:this.i18n2('greatOrEqual','大于等于'),value:'GE'},
                    {label:this.i18n2('isEmpty','为空'),value:'ISNULL'},
                    {label:this.i18n2('isNotEmpty','不为空'),value:'NOTNULL'}
                ],
                'select':[
                    {label:this.i18n2('include','包含'),value:'IN'},
                    {label:this.i18n2('notInclude','不包含'),value:'NIN'},
                    {label:this.i18n2('isEmpty','为空'),value:'ISNULL'},
                    {label:this.i18n2('isNotEmpty','不为空'),value:'NOTNULL'}
                ],
                'treeselect':[
                    {label:this.i18n2('include','包含'),value:'IN'},
                    {label:this.i18n2('notInclude','不包含'),value:'NIN'},
                    {label:this.i18n2('isEmpty','为空'),value:'ISNULL'},
                    {label:this.i18n2('isNotEmpty','不为空'),value:'NOTNULL'}
                ],
                'dialog':[
                    {label:this.i18n2('include','包含'),value:'IN'},
                    {label:this.i18n2('notInclude','不包含'),value:'NIN'},
                    {label:this.i18n2('isEmpty','为空'),value:'ISNULL'},
                    {label:this.i18n2('isNotEmpty','不为空'),value:'NOTNULL'}
                ],
                'number':[
                    {label:this.i18n2('eq','等于'),value:'EQ'},
                    {label:this.i18n2('neq','不等于'),value:'NEQ'},
                    {label:this.i18n2('lessThan','小于'),value:'LT'},
                    {label:this.i18n2('lessOrEqual','小于等于'),value:'LE'},
                    {label:this.i18n2('greater','大于'),value:'GT'},
                    {label:this.i18n2('greatOrEqual','大于等于'),value:'GE'},
                    {label:this.i18n2('isEmpty','为空'),value:'ISNULL'},
                    {label:this.i18n2('isNotEmpty','不为空'),value:'NOTNULL'}
                ],
                'user':[
                    {label:this.i18n2('include','包含'),value:'IN'},
                    {label:this.i18n2('notInclude','不包含'),value:'NIN'},
                    {label:this.i18n2('isEmpty','为空'),value:'ISNULL'},
                    {label:this.i18n2('isNotEmpty','不为空'),value:'NOTNULL'}
                ],
                'group':[
                    {label:this.i18n2('include','包含'),value:'IN'},
                    {label:this.i18n2('notInclude','不包含'),value:'NIN'},
                    {label:this.i18n2('isEmpty','为空'),value:'ISNULL'},
                    {label:this.i18n2('isNotEmpty','不为空'),value:'NOTNULL'}
                ],
                'checkboxgroup':[
                    {label:this.i18n2('include','包含'),value:'IN'},
                    {label:this.i18n2('notInclude','不包含'),value:'NIN'},
                    {label:this.i18n2('isEmpty','为空'),value:'ISNULL'},
                    {label:this.i18n2('isNotEmpty','不为空'),value:'NOTNULL'}
                ],

            },
            scriptMethod:"",
            showScript:false,
            scriptRow:{},
            defaultBtnI18ns:ApiFormCoreLang.apiFormCore.defaultBtnI18ns
        }
    }
}